package de.karlNet.login.attributeMapper;

import java.util.List;

import javax.naming.NamingException;
import javax.naming.directory.Attributes;

import org.springframework.stereotype.Component;

import de.karlNet.sambamanager.ldapModel.LdapContainer;
import de.karlNet.sambamanager.ldapModel.LdapObject;

@Component
public class ContainerExtractor extends LdapObjectExtractor {
	private LdapContainer getLdapContainer(Attributes attributes)
			throws NamingException {
		String dn = this.tryToGetString("distinguishedname", attributes,
				tryToGetString("dn", attributes));
		String cn = this.tryToGetString("name", attributes,
				tryToGetString("cn", attributes));
		return new LdapContainer(cn, dn);
	}
	
	@Override
	public LdapObject extract(Attributes attributes, List<String> objectClasses)
			throws NamingException {
		if (objectClasses.contains("organizationalUnit")
				|| objectClasses.contains("container")) {
			return this.getLdapContainer(attributes);
		}
		return null;
	}

}
